package com.tangyuan.ai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tangyuan.ai.entity.model.AiModel;
import com.tangyuan.ai.entity.vo.AiModelVo;
import com.tangyuan.ai.mapper.AiModelMapper;
import com.tangyuan.ai.service.AiModelService;
import com.tangyuan.common.util.StringUtils;
import com.tangyuan.dto.PageDto;
import org.springframework.stereotype.Service;


import java.util.List;


@Service
public class AiModelServiceImpl extends ServiceImpl<AiModelMapper, AiModel> implements AiModelService{
    @Override
    public List<AiModelVo> getPageAiModel(PageDto dto) {
        QueryWrapper<AiModel> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(AiModel::getIsEnabled,0);
        wrapper.lambda().orderByAsc(AiModel::getSort);
        return baseMapper.getPageAiModel(new Page<>(dto.getPageNum(),dto.getPageSize()),wrapper).getRecords();
    }

    @Override
    public AiModel getAiModelById(Integer id) {
        return baseMapper.selectById(id);
    }

    @Override
    public AiModel getAiModelByModelName(String modelName, Integer id) {
        if(StringUtils.isEmpty(modelName)){
            return null;
        }
        return baseMapper.getAiModelByModelName(modelName, id);
    }

    @Override
    public AiModel saveAiModel(AiModel model,String modelName) {
        AiModel aiModel = new AiModel();
        aiModel.setModelName(modelName);
        aiModel.setModel(modelName);
        baseMapper.insert(aiModel);
        return aiModel;
    }

}
